package org.pro.Model;

import java.awt.*;
import java.io.Serializable;

public class Element implements IElement, Serializable {
    public double x;
    public double y;
    public int width = 10;
    public int height = 10;
    public boolean Destroyed = false;
    public static final long serialVersionUID = 1L;
    transient public Graphics2D graphics;
    transient public Object panel;

    public Element() {
    }



    public void update(double timeFlaps) {
    }

    public void draw(Graphics2D g, Object panel) {
    }

    public void destroy() {
        this.Destroyed = true;
    }

    public void move(double dir, double len) {
        this.x += len * Math.cos((dir - 90.0) * Math.PI / 180.0);
        this.y += len * Math.sin((dir - 90.0) * Math.PI / 180.0);
    }

    public double distance(Element target) {
        double a = this.x - target.x;
        double b = this.y - target.y;
        return Math.sqrt(a * a + b * b);
    }

    public double angle(Element target) {
        double len_x = target.x - this.x;
        double len_y = target.y - this.y;
        double radian = Math.atan2(len_y, len_x);
        return radian * 180.0 / Math.PI;
    }

    public Rectangle getRect() {
        return new Rectangle((int)(this.x - (double)(this.width / 2)), (int)this.y - this.height / 2, this.width, this.height);
    }
}
